<script type="text/javascript">
Ext.onReady(function(){
	Ext.QuickTips.init();

	var proxy = new Ext.data.HttpProxy({
		url: "<?php echo $this->baseUrl() . "categorias/index/?format=json";?> ",
		method: 'POST'
	});

	var recordFields = [
		{name: 'id', mapping: 'id'},
		{name: 'descricao', mapping: 'descricao'},
		{name: 'pai', mapping: 'pai'}
	];

	var categoriasStore = new Ext.data.JsonStore({
		proxy: proxy,
		storeId: 'myStore',
		root: 'categorias',
		autoLoad: true,
		totalProperty: 'totalRows',
		remoteSort: true,
		fields: recordFields,
		idProperty: 'id'
	});

	var columnModel = [
		{
			header: 'Descrição',
			dataIndex: 'descricao',
			sortable: true
		}, {
			header: 'Pai',
			dataIndex: 'pai',
			sortable: true
		}
	];

	var pagingToolbar = {
		xtype: 'paging',
		store: categoriasStore,
		pageSize: 50,
		displayInfo: true
	};

	var grid = {
		xtype: 'editorgrid',
		columns: columnModel,
		id: 'myEditor',
		store: categoriasStore,
		loadMask: true,
		bbar: pagingToolbar,
		stripeRows: true
	}

	new Ext.Window({
		width: 300,
		height: 300,
		border: false,
		layout: 'fit',
		items: grid
	}).show();
});
</script>
